#include "calculatordialog.h"
#include "ui_calculatordialog.h"

CalculatorDialog::CalculatorDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CalculatorDialog)
{
    ui->setupUi(this);
    ui->m_editX->setValidator(new QDoubleValidator(this));
    ui->m_editY->setValidator(new QDoubleValidator(this));
    connect(ui->m_editX,SIGNAL(textChanged(QString)),
            this,SLOT(enableButton()));
    connect(ui->m_editY,SIGNAL(textChanged(QString)),
            this,SLOT(enableButton()));
    connect(ui->m_button,SIGNAL(clicked()),
            this,SLOT(calcClicked()));
}

CalculatorDialog::~CalculatorDialog()
{
    delete ui;
}

void CalculatorDialog::enableButton()
{
    bool bXok,bYok;
    ui->m_editX->text().toDouble(&bXok);
    ui->m_editY->text().toDouble(&bYok);
    ui->m_button->setEnabled(bXok&&bYok);
}

void CalculatorDialog::calcClicked()
{
    double res = ui->m_editX->text().toDouble()+
            ui->m_editY->text().toDouble();
    QString str = QString::number(res);
    ui->m_eidtZ->setText(str);
}
